<template>
  <div>
    <!-- 上 -->
    <el-card  class="co-middle">
          <el-form :inline="true"  class="demo-form-inline">
             <el-form-item label="员工账号:" >
    <el-input v-model="pageing.employeeNumber" placeholder="请输入员工账号" ></el-input>
  </el-form-item >
  <el-form-item label="员工姓名:" label-width="180px">
      <el-input v-model="pageing.name" placeholder="请输入员工姓名" ></el-input>
  </el-form-item >
   <el-form-item label="工作模式:"  label-width="240px">
    <el-select v-model="form" placeholder="请选择工作模式" value-key="id">
      <el-option v-for="item in list" :key="item.id" :label="item.name" :value="item.id"></el-option>
    </el-select>
  </el-form-item>
        </el-form>
        <!--  -->
        <el-form :inline="true" :model="formInline" class="demo-form-inline-two" label-width="70px">

  <el-form-item label="月份:" >
   <el-date-picker
      v-model="value2"
      type="month"
      placeholder="请选择月份">
    </el-date-picker>
    <!-- <el-input v-model="formInline.user" placeholder="请输入车辆类型"></el-input> -->
  </el-form-item>
   <el-form-item label="所属机构:"  label-width="160px">
    <template>
      <Treeselect
      style="margin-left:10px;"
       class="treeselect-main"
                :options="tree"
                v-model="pageing.workPatternId"
                :normalizer="normalizer"
                placeholder="请选择起始地机构"
                 :append-to-body="true"
              />
     </template>
  </el-form-item>
   <el-form-item class="anniu">
   <template #default="{row}">
     <el-button type="danger" @click="search(row)">搜索</el-button>
    <el-button @click="reset">重置</el-button>
   </template>
  </el-form-item>
       </el-form>
      </el-card>
      <!-- 下 -->
     <div>
       <el-card>
        <el-row style="margin-bottom:20px;">
           <!-- <template #default="{row}"> -->
           <el-button  type="danger"  @click="$router.push(`workforcemanagement/workArrangeInfo/`)">排班设置</el-button>
          <el-button @click="bind">绑定排班</el-button>
           <!-- </template> -->
        </el-row>

        <!-- tab表格 -->
  <el-table  :header-cell-style="{background:'#f8faff',color:'#818693'}"  :data="tableData" tooltip-effect="dark" style="width: 100%" stripe @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55"></el-table-column>
    <el-table-column label="员工账号" width="120" fixed prop="employeeNumber">
      <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
    </el-table-column>
    <el-table-column prop="name" label="员工姓名" width="120" fixed> </el-table-column>
    <el-table-column prop="phone" label="员工电话" show-overflow-tooltip width="120" fixed> </el-table-column>
    <el-table-column prop="userType" label="员工角色" width="120" fixed :formatter="formatRole"> </el-table-column>
    <el-table-column prop="workPatternName" label="当前工作模式" width="120" fixed> </el-table-column>
    <!-- 渲染列 -->
    <el-table-column prop="workSchedules" :label="`${item}`" width="120"
    v-for="(item,index) in 31" :key="index">
      <template #default="{row}">
              <div  :class="row.workSchedules[index] ? 'work' : 'rest'">
                <div>{{row.workSchedules[index]?'上':'休'}}</div>
              </div>
            </template>
     </el-table-column>
  </el-table>
   <!-- 分页 -->
       <el-pagination
       class="page"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageing.page"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="pageing.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
      </el-card>
     </div>
     <!-- 绑定 -->
     <el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="35%">
 <el-row type="flex" >
  <el-radio size="medium" v-model="radio" label="1" style="margin-left:50px;">礼拜制</el-radio>
  <el-radio v-model="radio" label="2" style="margin-left:50px;">连续制</el-radio>
 </el-row>
 <el-row style=" margin-top: 30px;margin-left:40px;" type="flex">
  <span class="moshi">模式名称:</span>
  <el-select v-model="form" placeholder="请选择" style="width:300px">
    <el-option
      v-for="item in values"
      :key="item.id"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
 </el-row>
  <span slot="footer" class="dialog-footer">
    <el-button type="danger" @click="dialogVisible = false">确 定</el-button>
    <el-button  @click="dialogVisible = false">取 消</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import freightmanagement from '@/api/constant/freightmanagement'
import { getRowClassInfo, workingMode } from '@/api/workforce'
import { treeShapedApi } from '@/api/institution'
export default {
  name: 'workforce-management',
  components: { Treeselect },
  data () {
    return {
      total: 0,
      options: [],
      radio: 1,
      dialogVisible: false,
      list: [],
      tree: [],
      value: '',
      freightmanagement,
      value2: '',
      formInline: {
        user: '',
        region: ''
      },
      tableData: [],
      pageing: {
        page: 1,
        pageSize: 10,
        workPatternId: null,
        name: '',
        employeeNumber: ''
      },
      form: {},
      values: {}
    }
  },
  computed: {},
  methods: {
    handleSizeChange (newSize) {
      this.pageing.pageSize = newSize
      this.rowClass()
    },
    handleCurrentChange (newPage) {
      this.pageing.page = newPage
      this.rowClass()
    },
    upClass (row, column) {
      // console.log(row.workSchedules)
      // console.log(column)
      if (row.workSchedules === true) {
        return row.workSchedules === '上'
      } else if (row.workSchedules === false) {
        return row.workSchedules === '休'
      }
      // this.tableData.workSchedules.filter(item => {
      //   console.log(item.workSchedules)
      //   if (item.workSchedules === true) {
      //     return item.workSchedules === '上'
      //   } else {
      //     return item.workSchedules === '休'
      //   }
      //   // return console.log(item)
      // })
    },
    // 员工角色处理
    formatRole: function (row, column) {
      // console.log(row)
      if (row.userType === 1) {
        return '员工'
      } else if (row.userType === 2) {
        return '快递员'
      } else {
        return '司机'
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    // 列表渲染
    async  rowClass () {
      const res = await getRowClassInfo({ ...this.pageing })
      console.log(res)
      this.tableData = res.data.items
      this.total = +res.data.counts
      // this.xiu = res.data.items.workSchedules
      // console.log(this.xiu)
      const re = await workingMode()
      console.log(re)
      this.form = re.data
      // console.log(this.form[1])
      // console.log(this.form[2])
      this.list = [
        ...this.form[1],
        ...this.form[2]
      ]
      // this.value = this.form.id
      // console.log(this.list)
    },
    // 下拉树形结构
    async initTree () {
      const res = await treeShapedApi()
      this.tree = JSON.parse(res.data)
      // console.log(this.tree)
    },
    normalizer (node) {
      // console.log(node)
      // 当子节点也就是children=[]时候去掉子节点
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children && node.children.length > 0 ? node.children : 0
      }
    },
    // 搜索
    async search (row) {
      // this.rowClass()
      console.log(row)
      const res = await getRowClassInfo({ ...this.pageing })
      console.log(res)
      this.tableData = res.data.items
      // this.form = this.tableData
    },
    // 重置
    reset () {
      this.pageing = {
        workPatternId: '',
        name: '',
        employeeNumber: ''
      }
      this.rowClass()
    },
    // 绑定
    async bind () {
      this.dialogVisible = true
      const re = await workingMode()
      console.log(re)
      this.values = re.data
    }

  },
  created () {
    this.rowClass()
    this.initTree()
  }
}
</script>

<style lang="scss" scoped>
.anniu {
  margin-left: 50px;
}
::v-deep .vue-treeselect__control {
    // padding-left: 5px;
    // padding-right: 5px;
    display: table;
    table-layout: fixed;
    /* width: 100%; */
    width: 220px;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #fff;
    transition-duration: 200ms;
    transition-property: border-color, box-shadow, width, height, background-color, opacity;
    transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
}
.work {
  width: 24px;
    height: 24px;
    background: rgb(255, 238, 235);
    border: 1px solid rgb(225, 85, 54);
    border-radius: 50%;
    text-align: center;
    color: rgb(225, 85, 54);
    font-size: 13px;
}
.rest {
  width: 24px;
    height: 24px;
    background: rgb(239, 243, 248);
    border: 1px solid rgb(216, 221, 227);
    border-radius: 50%;
    text-align: center;
    color: rgb(32, 35, 42);
    font-size: 13px;
}
::v-deep .el-dialog__footer {
  text-align: center;
}
.moshi {
      text-align: right;
    vertical-align: middle;
    float: left;
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 0;
    // -webkit-box-sizing: border-box;
    box-sizing: border-box;
}
::v-deep .el-radio__inner {
      border-color: #e15536;
    // background: #e15536;
    border: 1px solid #dcdfe6;
    border-radius: 100%;
    width: 14px;
    height: 14px;
}
.page {
  text-align: center;
}
</style>
